home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / facnum.doc < prev    next >
Text File  |  1995-03-31  |  1KB  |  32 lines

  1. Article: 4251 of comp.sys.handhelds 
  2. Author: Mark Adler (madler@piglet.caltech.edu) 
  3. Subject: Breaking out of loops on the HP-48SX 
  4. Date: 11 Nov 90 00:27:58 GMT 
  5. Organization: California Institute of Technology, Pasadena 
  6.  
  7. I just discovered a technique that I thought I'd share.  The HP-48SX 
  8. appears to lack a way to break out of loops.  But appearances can be 
  9. deceiving.  There is a kludgey way to do it.  You can put the loop 
  10. in an IFERR statement, and then divide by zero or some such thing to 
  11. cause an error.  This appears to cleanly exit the loop (or loops). 
  12. As an example of this tehcnique, here is a program (FACNUM) which 
  13. will take a whole number and return its prime factorization as a 
  14. list of primes, repeated if necessary.  I wanted to avoid having the 
  15. inner loop do two tests, so it could be a simple FOR loop, and so 
  16. the loop exit is done inside IF statements with a divide by zero. 
  17.  
  18. A note to HP: please include a throw/catch operation for exiting 
  19. loops on the next calculator (48SY?  49?).  The code to handle 
  20. cleaning up leftover constructs appears to already be there for 
  21. IFERR.  Thanks. 
  22.  
  23. Mark Adler 
  24. madler@piglet.caltech.edu 
  25.  
  26. [Note: Mark's FACNUM program is about twice as fast as my PF on the HORN1 
  27.        disk.  Good work, Mark!  Now who will write it in ML??  -jkh-] 
  28.  
  29. [Later note: Klaus Kalb did!  See TRIAL on this disk.  -jkh-] 
  30.  
  31. [Even later note: Jurjen Bos perfected it; see FACTOR.  -jkh-] 
  32.